<template>
	<view class="ybTips">
		<view class="main">
			<view class="title"> 请投入硬币 </view>
			<view class="money_total">{{ `应付款：${payable}` }}</view>
			<view class="money_total">
				{{ `已投入 ${countMoney(messageArr)} 圆` }}</view
			>
			<div class="btn_box">
				<view
					class="btn"
					@click="confirm"
					>确定</view
				>
			</div>
		</view>
	</view>
</template>

<script>
import { countMoney } from '@/utils/countMoney';
import { watch } from 'vue';
import { saveSlotLog } from '@/api/order';
import { zbCode, ybCode, zlCode, stateCode } from '@/config/code';
export default {
	props: {
		payable: {
			default: 0,
		},
		orderNo: {
			default: '',
		},
	},
	data() {
		return {};
	},
	watch: {
		payable: {
			handler(newName, oldName) {
				if (newName < countMoney(this.$props.messageArr)) {
					const zl = newName - countMoney(this.$props.messageArr);
					this.$emit('tbSuccess', { type: 'zb', change: zl });
				}
				console.log('newName', newName);
			},
			immediate: true,
		},
	},
	mounted() {},
	methods: {
		jump(data) {
			let url = '';
			switch (data) {
				case 'service':
					url = '/pages/service/service';
					break;
				default:
			}
			uni.navigateTo({ url });
		},
		cancel() {},
		confirm() {
			this.$emit('handConform', 'yb');
		},
		// 计算投币总额
		async countMoney(data) {
			const equipmentOptions = JSON.parse(
				uni.getStorageSync('equipmentOptions')
			);
			let _total = 0;
			data.map(item => {
				_total += countMoney(item, this.total);
			});
			this.baseTotal = _total;
			// 后台通信记录投币记录
			if (
				data === zbCode.money_100 ||
				data === zbCode.money_500 ||
				data === zbCode.money_1000 ||
				data === ybCode.money_50
			) {
				const params = {
					store_id: equipmentOptions.store_id,
					order_no: this.$props.orderNo,
					equipmentID: equipmentID.equipmentID,
					amount: this.$props.payable,
					amount_type: 2,
					type: 1,
					num: 1,
					denomination: data,
				};
				await saveSlotLog(params).then(res => {});
			}
			return _total;
		},
	},
};
</script>

<style lang="scss" scoped>
.ybTips {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 99;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
	.main {
		// width: 100%;
		// height: 100%;
		padding: 30rpx 60rpx;
		border: 2rpx solid $uni-color-green;
		border-radius: 10rpx;
		color: $uni-color-green;
		background-color: $uni-color-white;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.title {
			width: 400rpx;
			height: 150rpx;
			text-align: center;
			line-height: 150rpx;
		}
		.money_total {
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
		}
		.content {
			width: 400rpx;
			min-height: 150rpx;
			text-align: center;
			line-height: 2;
		}
		.btn_box {
			width: 400rpx;
			height: 100rpx;
			margin-top: 30rpx;
			display: flex;
			justify-content: center;

			.btn {
				height: 30rpx;
				padding: 20rpx;
				line-height: 1;
				border-radius: 10rpx;
				color: $uni-color-white;
				background-color: $uni-color-green;
			}
		}
	}
}
</style>
